home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / SOURCE.ZIP / KILDIA.ASM < prev    next >
Assembly Source File  |  1989-06-24  |  9KB  |  541 lines

  1.  
  2. memS    equ 1           ;model small  convertable to COM model
  3. ;****************    RUNTIME LIBRARY OF KILLDIANA.COM     **************
  4. include lcmac.mac
  5. calln    macro    name
  6.     call near ptr name
  7.     endm
  8. callp    macro    name
  9.     lea    dx,name
  10.     calln    print
  11.     endm
  12. callz    macro    name
  13.     push    si
  14.     lea    si,name
  15.     calln    printz
  16.     pop    si
  17.     endm
  18.  
  19. dgroup    group data,udata,xstack
  20.     assume ds:data
  21.  
  22. pgroup    group prog,tail
  23. prog    segment byte public 'prog'
  24.     assume cs:prog
  25.  
  26.     org    100h            ;FOR MODEL COM
  27.  
  28. start    label     far
  29.     cli
  30.     mov    ax,offset pgroup:xtail    ;get end of code group
  31.     add    ax,16            ;calculate segment address of ds
  32.     mov    cl,4            ;calculate segment address of ds
  33.     shr    ax,cl            ;calculate segment address of ds
  34.     mov    bx,cs            ;calculate segment address of ds
  35.     add    ax,bx            ;calculate segment address of ds
  36.     mov    ds,ax            ;set ds to dgroup
  37.     mov    es,ax            ;set es to dgroup
  38.     mov    ss,ax            ;set ss to dgroup
  39.     mov    ds:_ss,ax        ;save stack segment for (do,for,while)
  40.     mov    sp,offset dgroup:sbase + 512    ;range of stack = 512 bytes
  41.     mov    ds:_top,sp        ;save stack pointer for (do,for,while)
  42.     mov    bx,offset dgroup:sbase    ;get  stack segment for (do,for,while)
  43.     mov    ds:_base,bx        ;save stack segment for (do,for,while)
  44.     sti
  45.     mov    ah,30h            ;get dos version number
  46.     int    21h
  47.     mov    ds:_dos,ax        ;save dos version for (do,for,while)
  48.     callp    copyr
  49.     callp    tryrem
  50.     calln    remove
  51.     callp    weak
  52.  
  53.     lea    di,fname
  54.     mov    si,82h
  55. getf:
  56.     mov    al,cs:[si]
  57.     cmp    al,0dh
  58.     je    tonul
  59.     cmp    al,' '
  60.     jc    blank
  61.     mov    [di],al
  62.     inc    di
  63. blank:    inc    si
  64.     .br    getf
  65. tonul:    clr    al
  66.     mov    [di],al
  67.     calln    prefix
  68.     calln    comwrk
  69. ;    calln    exewrk
  70.     mov    ah,4ch
  71.     int    21h        ;exit to DOS
  72.  
  73. print    proc    near
  74.     mov    ah,9
  75.     int    21h
  76.     ret
  77. print    endp
  78.  
  79. comwrk    proc    near
  80.     calln    first
  81.     jc    toret
  82.     calln    workcom
  83. ffnext:
  84.     calln    fnext
  85.     jc    toret
  86.     calln    workcom
  87.     .br    ffnext
  88. toret:
  89.     ret
  90. comwrk    endp
  91. fnext    proc    near
  92.     mov    ah,4fh        ;findnext
  93.     int    21h
  94.     jc    ercc
  95.     jnc    foundf
  96. fnext    endp
  97. first    proc    near
  98.     lea    dx,fname
  99.     mov    cx,27h        ;search all types of files
  100.     mov    ah,4eh        ;findfirst
  101.     int    21h
  102.     jnc    foundf
  103.     callp    notfnd
  104. ercc:    stc
  105.     ret
  106. foundf:
  107.     calln    konka
  108.     clc
  109.     ret
  110. first    endp
  111. konka    proc    near
  112.     mov    ah,2fh
  113.     int    21h        ;get dta  in es:bx
  114.     add    bx,26
  115.     mov    ax,es:[bx]
  116.     mov    llfil,ax    ;save lowlengh
  117.     inc    bx
  118.     inc    bx
  119.     mov    ax,es:[bx]
  120.     mov    lhfil,ax    ;save highlengh
  121.     inc    bx
  122.     inc    bx        ;pointed to fname
  123.     lea    si,ffname
  124.     lea    di,fname
  125.     push    es
  126.     push    ds
  127.     pop    es
  128.     mov    cx,40h
  129. repe    cmpsb
  130.     pop    es
  131.     dec    si
  132. copyf:    mov    al,es:[bx]
  133.     mov    [si],al
  134.     inc    si
  135.     inc    bx
  136.     or    al,al
  137.     jne    copyf
  138.     ret
  139. konka    endp
  140.  
  141. prefix    proc    near
  142.     lea    si,fname
  143.     add    si,40h
  144.     mov    cx,40h
  145.     std
  146. lodi:
  147.     lodsb
  148.     cmp    al,'\'
  149.     je    founds
  150.     cmp    al,':'
  151.     je    founds
  152.     loop    lodi
  153.     mov    nepar,offset fname
  154.     .br    endcp
  155. founds:
  156.     inc    si
  157.     inc    si
  158.     mov    nepar,si
  159.     lea    si,fname
  160.     lea    di,ffname
  161. cpag:
  162.     cmp    si,nepar
  163.     jae    endcp
  164.     mov    al,[si]
  165.     mov    [di],al
  166.     inc    si
  167.     inc    di
  168.     .br    cpag
  169. endcp:
  170.     cld
  171.     ret
  172. prefix    endp
  173.  
  174.  
  175. remove    proc    near
  176.     push    ds
  177.     clr    ax
  178.     mov    ds,ax
  179.     les    bx,ds:[84h]       ;21h vector
  180.     mov    ax,cs
  181.     mov    dx,es
  182.     cmp    dx,ax
  183.     jc    nodia
  184.     cmp    bx,2eeh
  185.     jne    nodia
  186.  
  187.     mov    ax,es:[74fh]
  188.     mov    ds:[84h],ax       ;restore 21h
  189.     mov    ax,es:[751h]
  190.     mov    ds:[86h],ax
  191.  
  192.     mov    ax,es:[74bh]
  193.     mov    ds:[9ch],ax       ;restore 27h
  194.     mov    ax,es:[74dh]
  195.     mov    ds:[9eh],ax
  196.     mov    ax,es
  197.     mov    bx,ax
  198.     dec    ax
  199.     mov    es,ax
  200.     mov    es:byte ptr[0],5ah
  201.     mov    es:word ptr[1],0
  202.     pop    ds
  203.     callp    diakt
  204.     ret
  205. nodia:
  206.     pop    ds
  207.     callp    dinakt
  208.     ret
  209. remove    endp
  210.  
  211. workcom proc    near
  212.     lea    dx,ffname
  213.     mov    ax,4300h    ;get attrib
  214.     int    21h
  215.     jnc    kopa
  216.     jmp    retga
  217. kopa:
  218.     mov    al,cl
  219.     and    al,0feh
  220.     cmp    al,cl
  221.     je    nochatr
  222.  
  223.     mov    attr,cx
  224.     mov    ax,4301h    ;set attrib
  225.     clr    cx        ;to normal
  226.     int    21h
  227.     .br    nochh
  228. nochatr:
  229.     mov    attr,0
  230. nochh:
  231.     mov    ax,3d02h    ;open file R/W
  232.     int    21h
  233.     jnc    kop1
  234.     jmp    resatr
  235. kop1:    mov    bx,ax
  236.     calln    gettm
  237.     mov    cx,18h
  238.     lea    dx,bufer
  239.     mov    ah,3fh        ;read first 3 bytes
  240.     int    21h
  241.     jc    closs2
  242.     mov    di,dx
  243.     mov    ax,ds:[di]
  244.     cmp    ax,5a4dh
  245.     jne    commfil
  246.     push    bx
  247.     calln    exework
  248.     pop    bx
  249.     jc    chek2
  250.     jmp    closs
  251.  
  252. commfil:
  253.     mov    al,ds:[di]
  254.     cmp    al,0e9h
  255.     je    mak111
  256.     jmp    closs
  257. mak111: mov    si,ds:[di+1]    ;relative offset
  258.     add    si,3
  259.     mov    di,si
  260.     sub    si,68h
  261.     mov    len,si
  262.  
  263.     clr    cx
  264.     mov    dx,di
  265.     mov    ax,4200h
  266.     int    21h        ;seek to found e80000
  267. closs2: jc    clos21
  268.  
  269.     lea    dx,bufer
  270.     add    dx,18h+3
  271.     mov    cx,7        ;read 7 bytes
  272.     mov    ah,3fh
  273.     int    21h        ;read
  274. clos21: jnc    chek1
  275. chek2:    jmp    closs
  276. chek1:
  277.     mov    di,dx
  278.     cmp    ds:byte ptr[di],0e8h
  279.     jne    chek2
  280.     cmp    ds:word ptr[di+1],0
  281.     jne    chek2
  282.     cmp    ds:word ptr[di+4],0ee81h
  283.     jne    chek2
  284.     cmp    ds:word ptr[di+6],6bh
  285.     jne    chek2
  286.  
  287.     clr    cx
  288.     mov    dx,si
  289.     add    dx,705h
  290.     mov    ax,4200h
  291.     int    21h        ;seek to found org 3bytes
  292.     jc    closs
  293.     lea    dx,bufer
  294.     add    dx,18h
  295.     mov    cx,3        ;read 3 bytes
  296.     mov    ah,3fh
  297.     int    21h        ;read
  298.     jc    closs
  299.     lea    si,bufer
  300. restor3:
  301.     mov    al,[si+18h]
  302.     mov    [si],al
  303.     inc    si
  304.     loop    restor3
  305.     clr    cx
  306.     clr    dx
  307.     mov    ax,4200h    ;seek to begin
  308.     int    21h
  309.     jc    closs
  310.  
  311.     mov    cx,18h
  312.     lea    dx,bufer
  313.     mov    ah,40h        ;write
  314.     int    21h
  315.     jc    closs
  316.  
  317.     clr    cx
  318.     mov    dx,len
  319.     mov    ax,4200h    ;seek to end of real data
  320.     int    21h
  321.     jc    resatr
  322. exelen:
  323.     clr    cx
  324.     mov    ah,40h        ;truncate file
  325.     int    21h
  326.     push    bx
  327.     callp    file
  328.     callz    ffname
  329.     callp    isok
  330.  
  331.     pop    bx
  332. closs:
  333.     calln    settm
  334.     mov    ah,3eh
  335.     int    21h        ;close file
  336.  
  337. resatr:
  338.     mov    cx,attr     ;to old attributes
  339.     or    cx,cx
  340.     je    retga
  341.     lea    dx,ffname
  342.     mov    ax,4301h    ;set attrib
  343.     int    21h
  344. retga:
  345.     ret
  346. workcom endp
  347. printz    proc    near
  348. eter:    mov    ah,2
  349.     lodsb
  350.     or    al,al
  351.     je    caret
  352.     mov    dl,al
  353.     int    21h
  354.     .br    eter
  355. caret:
  356.     ret
  357. printz    endp
  358.  
  359. gettm    proc    near
  360.     mov    ax,5700h
  361.     int    21h
  362.     jc    qget
  363.     mov    atcx,cx
  364.     mov    atdx,dx
  365. qget:
  366.     ret
  367. gettm    endp
  368.  
  369. settm    proc    near
  370.     mov    ax,5701h
  371.     mov    cx,atcx
  372.     mov    dx,atdx
  373.     or    cx,cx
  374.     je    qset
  375.     or    dx,dx
  376.     je    qset
  377.     int    21h
  378. qset:
  379.     ret
  380. settm    endp
  381. exework proc    near
  382.     mov    ax,[di+16h]      ;get main lenght in pargarphs
  383.     mov    cx,16
  384.     mul    cx
  385.     push    bx
  386.     mov    bx,[di+8]
  387.     mov    cl,4
  388.     shl    bx,cl
  389.     add    ax,[di+14h]      ;get IP
  390.     adc    dx,0
  391.     add    ax,bx
  392.     adc    dx,0
  393.     pop    bx
  394.     mov    exhlen,dx
  395.     mov    exllen,ax
  396.     mov    cx,dx
  397.     mov    dx,ax
  398.     mov    ax,4200h
  399.     int    21h        ;seek to begin Diana code
  400.  
  401.     lea    dx,bufer
  402.     add    dx,18h+3
  403.     mov    cx,7        ;read 7 bytes
  404.     mov    ah,3fh
  405.     int    21h        ;read
  406.     jc    echek2
  407.     mov    di,dx
  408.     cmp    ds:byte ptr[di],0e8h
  409.     jne    echek2
  410.     cmp    ds:word ptr[di+1],0
  411.     jne    echek2
  412.     cmp    ds:word ptr[di+4],0ee81h
  413.     jne    echek2
  414.     cmp    ds:word ptr[di+6],6bh
  415.     je    exgoin
  416. echek2:
  417.     stc
  418.     ret
  419. exgoin:
  420.     sub    exllen,68h
  421.     sbb    exhlen,0    ;contains lenght of file
  422.  
  423.     mov    dx,exllen
  424.     mov    cx,exhlen
  425.     add    dx,707h
  426.     adc    cx,0
  427.     mov    ax,4200h
  428.     int    21h        ;seek to old vectors
  429.     lea    dx,bufer
  430.     add    dx,26h
  431.     mov    cx,1
  432.     mov    ah,3fh
  433.     int    21h        ;read    old cs:ip,  ss:sp
  434.     jc    echek2
  435.  
  436.     mov    dx,exllen
  437.     mov    cx,exhlen
  438.     add    dx,6fdh
  439.     adc    cx,0
  440.     mov    ax,4200h
  441.     int    21h        ;seek to old vectors
  442.     lea    dx,bufer
  443.     add    dx,18h
  444.     mov    cx,8
  445.     mov    ah,3fh
  446.     int    21h        ;read    old cs:ip,  ss:sp
  447.     jc    echek2
  448.  
  449.     mov    ax,llfil
  450.     mov    dx,lhfil
  451.     sub    ax,exllen
  452.     sbb    dx,exhlen
  453.     mov    lhfil,dx
  454.     mov    llfil,ax
  455.     lea    di,bufer
  456.     mov    ax,[di+4]
  457.     mov    cx,512
  458.     mul    cx
  459.     add    ax,[di+2]
  460.     adc    dx,0
  461.     sub    ax,llfil
  462.     sbb    dx,lhfil
  463.     div    cx
  464.     mov    cx,dx
  465.     mov    dl,[di+26h]
  466.     sub    cx,dx
  467.     mov    rema,cx
  468.     mov    [di+2],dx    ;store remainder of lenght
  469.     mov    [di+4],ax    ;store /512 lenght
  470.  
  471.     mov    ax,[di+18h]    ;get ip
  472.     mov    [di+14h],ax    ;store
  473.     mov    ax,[di+1ah]    ;get cs:
  474.     mov    [di+16h],ax    ;store
  475.  
  476.     mov    ax,[di+1ch]    ;get sp
  477.     mov    [di+10h],ax    ;store
  478.     mov    ax,[di+1eh]    ;get ss:
  479.     mov    [di+0eh],ax    ;store
  480.  
  481.     clr    cx
  482.     clr    dx
  483.     mov    ax,4200h
  484.     int    21h        ;seek to prefix
  485.     mov    cx,18h        ;to write new prefix
  486.     lea    dx,bufer
  487.     mov    ah,40h
  488.     int    21h        ;write 18h bytes prefix
  489.     mov    cx,exhlen
  490.     mov    dx,exllen
  491.     sub    dx,rema
  492.     sbb    cx,0
  493.     mov    ax,4200h
  494.     int    21h        ;seek end of file
  495.     jmp    exelen
  496. exework endp
  497.  
  498. prog    ends
  499.  
  500. tail    segment word 'prog'     ;help segment to allocate end of code
  501. xtail    dw    -1        ;and set the data segment
  502. tail    ends
  503.  
  504. data    segment para public 'data'     ;data segment
  505.  
  506. fname    db    40h dup(0)
  507. ffname    db    40h dup(0)
  508. bufer    db    27h dup(0)
  509. _ss    dw    ?    ;Lattice variables
  510. _base    dw    ?    ;Lattice variables
  511. _dos    dw    ?    ;Lattice variables
  512. _top    dw    ?    ;Lattice variables
  513. nepar    dw    0
  514. fhand    dw    0
  515. exhlen    dw    0
  516. exllen    dw    0
  517. llfil    dw    0
  518. lhfil    dw    0
  519. len    dw    0
  520. attr    dw    0
  521. atcx    dw    0
  522. atdx    dw    0
  523. rema    dw    0
  524. notfnd    db    'File not found',13,10,'$'
  525. copyr    db    'Dianakiller program V1.0  (C)Copyright Deny_Soft 1989',13,10,'$'
  526. tryrem    db    'Searching Diana in memory...',13,10,'$'
  527. diakt    db    'Diana found',7,' and removed extra',13,10,'$'
  528. dinakt    db    "Diana isn't active",13,10,"$"
  529. weak    db    'Searching for weak files...',13,10,'$'
  530. file    db    'File $'
  531. isok    db    9,9,' ... restored',13,10,'$'
  532.  
  533. data    ends
  534.     .pub    <_ss,_base,_dos,_top>    ;make external
  535. udata    segment public 'data'
  536. udata    ends
  537. xstack    segment 'data'
  538. sbase    dw    512 dup (?)
  539. xstack    ends
  540.     end    start
  541.